package cn.suxiaoxiang.suwebverify.config;

import cn.suxiaoxiang.suwebverify.SuWebVerify;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;

import java.io.File;
import java.util.Set;

/**
 * MessageConfig - 语言文件配置类
 *
 * @author 程序员-Su_xiaoxiang
 * @date 2025/4/7 19:18
 */
public class MessageConfig {
    public MessageConfig() {
    }
    private SuWebVerify plugin;
    private FileConfiguration playerCommandConfig;
    public MessageConfig(SuWebVerify plugin) {
        this.plugin = plugin;
    }

    /**
     * load  命令配置
     */
    public void loadPlayerCommandConfig() {
        File configFile = new File(plugin.getDataFolder(), "message.yml");

        if (!configFile.exists()) {
            // 假设你已经准备了默认的配置文件
            plugin.saveResource("message.yml", false);
        }
        try {
            // 加载配置
            playerCommandConfig = YamlConfiguration.loadConfiguration(configFile);
        } catch (Exception e) {
            plugin.getLogger().severe("[[WebExitPlayer]] 加载 message.yml 时发生错误: " + e.getMessage());
        }
    }

    /**
     * reload 命令配置
     */
    public void reloadPlayerCommandConfig() {
        File configFile = new File(plugin.getDataFolder(), "message.yml");

        if (configFile.exists()) {
            // 清空旧的配置对象
            playerCommandConfig = null;
            // 重新加载配置文件
            playerCommandConfig = YamlConfiguration.loadConfiguration(configFile);
        } else {
            plugin.getLogger().warning("[[WebExitPlayer]] message.yml 文件不存在！");
        }
    }
    /**
     * 获取配置中的消息
     */
    public FileConfiguration getPlayerCommandConfig() {
        return playerCommandConfig;
    }

}
